import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        int x = 1;
        while (x<10){
            try{
                throw new Exception("网络连接第"+x+"次");
            }catch (Exception e){
                    e.printStackTrace();
                    x++;
            }
        }
        System.out.println("连接成功");
    }


    //抛出自定义异常
    public static void fun(int x) throws ArithmeticException{
        if(x==0){
            throw new ArithmeticException("/0");
        }
    }
    public static void main2(String[] args) {
        int x = 10;
        int y = 0;
        try{
            fun(0);

        }catch (ArithmeticException e){
            e.printStackTrace();
        }finally {
            //x/=y;
        }
    }


    public static void main1(String[] args) {
        int[] arr = {1,2,3};
        try (Scanner scanner = new Scanner(System.in)) {
            int a = scanner.nextInt();
            System.out.println(arr[3]);
        } catch (NullPointerException | ArrayIndexOutOfBoundsException e) {
            //打印栈上面的信息
            e.printStackTrace();
            System.out.println("数组访问越界异常");
        } finally {
            System.out.println("啊哈哈哈");
        }
    }
}
